var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');

//定义数据库
// var InitDB = require('./sqlite/initdb');
// var SQLiteStore = require('connect-sqlite3')(session);
var SQLiteStore = require('connect-sqlite3')
var dbInit = require('./controller/init'); 

var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
//定义一个books路由
var booksRouter = require('./routes/books');

var app = express();

app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use('/', indexRouter);
app.use('/users', usersRouter);
//使用books路由
app.use('/books', booksRouter);

//注册中间件：创建数据库
app.use(dbInit());

module.exports = app;
